package com.example.config;

import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerContainerFactory;
import org.springframework.stereotype.Component;

import javax.jms.ConnectionFactory;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.Topic;

/**
 * @ClassName QueueConfig
 * @Description
 * @Author Jingxiao.Ye
 * @Date 2022/1/30 下午4:35
 * @Version V1.0
 * @Since JDK 11
 */
@Configuration
public class QueueConfig {

    @Bean
    public Queue queue() {
        return new ActiveMQQueue("queue-test");
    }

    @Bean
    public Topic topic(){
        return new ActiveMQTopic("topic-test");
    }

    @Bean
    public JmsListenerContainerFactory jmsListenerContainerTopicFactory(ConnectionFactory connectionFactory){
        DefaultJmsListenerContainerFactory defaultJmsListenerContainerFactory = new DefaultJmsListenerContainerFactory();
        defaultJmsListenerContainerFactory.setConnectionFactory(connectionFactory);
        defaultJmsListenerContainerFactory.setPubSubDomain(true);
        return defaultJmsListenerContainerFactory;
    }
}
